core: Fix possible crash in ostree_mutable_tree_walk()
authorSam Thursfield <ssssam@gmail.com>
Tue, 31 Mar 2015 16:59:43 +0000 (12:59 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 31 Mar 2015 17:04:31 +0000 (13:04 -0400)
If the starting index is beyond the end of the list, it's a programming
error. Previously, the code was trying to raise a runtime error, but
actually causing a segfault.

This was detected by test code in test-mutable-tree.c, which is removed
in this commit because it should now not be possible to crash here.

https://bugzilla.gnome.org/747032

src/libostree/ostree-mutable-tree.c
tests/test-mutable-tree.c

index 26a1ca442132effe06bf8af6c7ed3df0ac9571e9..17bcdc9ac73dc4a7a75e194d6823eeeb94a53aee 100644 (file)
@@ -315,11 +315,9 @@ ostree_mutable_tree_walk (OstreeMutableTree     *self,
                           OstreeMutableTree    **out_subdir,
                           GError               **error)
 {
-  if (start >= split_path->len)
-    {
-      return set_error_noent (error, (char*)split_path->pdata[start]);
-    }
-  else if (start == split_path->len - 1)
+  g_return_val_if_fail (start < split_path->len, FALSE);
+
+  if (start == split_path->len - 1)
     {
       *out_subdir = g_object_ref (self);
       return TRUE;
index ef2b6b5bff58d67f6588487d9a2817b7673f58d1..b0c23867c1c55a55048562ee0c32d5d0c1c9baa1 100644 (file)
@@ -68,13 +68,6 @@ test_mutable_tree_walk (void)
     g_clear_error (&error);
   }
 
-  {
-    gs_unref_object OstreeMutableTree *subdir = NULL;
-    g_assert_false (ostree_mutable_tree_walk (tree, split_path, 10, &subdir, &error));
-    g_assert_null (subdir);
-    g_clear_error (&error);
-  }
-
   {
     gs_unref_object OstreeMutableTree *subdir = NULL;
     gs_unref_object OstreeMutableTree *a = NULL;